package com.iflytek.iot.common.monitor.report.manager;

import com.iflytek.iot.common.monitor.model.MontiorCollectDataType;
import com.iflytek.iot.common.monitor.model.MontiorCollectDataTypeEnum;
import com.iflytek.iot.common.monitor.report.data.adapter.MybatisMonitorCollectDataAdapter;
import com.iflytek.iot.common.utils.JsonUtils;
import lombok.extern.slf4j.Slf4j;

/**
 * @author zurun
 * @date 2020/7/23 11:53:25
 */
@Slf4j
public class IotMybatisMonitorManager extends AbstractMonitorManager<MybatisMonitorCollectDataAdapter> {

    @Override
    public void add(MybatisMonitorCollectDataAdapter monitorStatistics) {
        compare(monitorStatistics);
    }

    @Override
    public String out() {
        return JsonUtils.toJSONString(this);
    }

    @Override
    public MontiorCollectDataType monitorType() {
        return MontiorCollectDataTypeEnum.IOT_MYBATIS;
    }

    @Override
    void notifyRefresh(int avg) {
        if (this.getMaxCost() > 100) {
            log.warn("[sql监控7] avg:{} max:{} {}", avg,this.getMaxCost(), JsonUtils.toJSONString(this));
        } else if (this.getMaxCost() > 1000) {
            log.error("[sql监控9] avg:{} max:{} {}", avg, this.getMaxCost(),JsonUtils.toJSONString(this));
        } else if (avg > 20) {
            log.warn("[sql监控5] avg:{} {}", avg, JsonUtils.toJSONString(this));
        } else {
            log.info("[sql监控0] avg:{} {}", avg, JsonUtils.toJSONString(this));
        }
    }
}
